<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
<script>
    //JS数据类型 = 原始类型 + 引用类型
    var a = 1;
    var b = 3.6;
    console.log(a,typeof a,b,typeof b);//整数小数都算number
    var c = "hello";
    var d = '你好呀~';
    console.log(c,typeof c,d,typeof d);//单引双引都算string
    var e = true;
    var f = false;
    console.log(e,typeof e,f,typeof f);//boolean
    var g;
    console.log(g,typeof g);//undefined访问未赋值的变量推断不出来类型就会得到“未定义型”

    //引用类型
    let obj = {};//定义空对象
    console.log(obj,typeof obj);//{} ‘object’
    let obj2 = {//定义带属性对象
        name:"张三",
        age:18
    };
    console.log(obj2,typeof obj2);
    console.log(obj2.name,obj2.age);
    obj2.like = '放春节';//JS还可以后期动态的新增属性
    console.log(obj2,obj2.like);
    console.log(obj2.play)//访问不存在的属性，得到undefined

    //JS数组
    let arr = ['周四',5,4.14,true];//JS数组
    console.log(arr,typeof arr);//[ '周四', 5, 4.14, true ] ‘object’
    console.log(arr[0],arr[1],arr[2],arr[3]);//周四 5 4.14 true
    console.log(arr[99]);//undefined    访问数组不存在的下标会得到undefined

    //Bollean()用于将参数转为布尔类型
    //0,undefined,null,空字符串，NaN这5个特殊值转为布尔都是false
    console.log(Boolean(0));//0转为false
    console.log(Boolean(undefined));//undefined转为false
    console.log(Boolean(null));//null转为false
    console.log(Boolean(''));//空字符串转为false
    console.log(Boolean(NaN));//NaN转为false
    console.log("--------------------");
    console.log(Boolean(1));//1转为true
    console.log(Boolean(' '));//空格转为true
    console.log(Boolean('上午好！'))//字符串转为true

    //Number()用于将参数转为数值类型，如果得不到数字结果，值为NaN(Not a Number)
    console.log(Number(true),typeof Number(true));//true转为1
    console.log(Number(false));//false转为0
    console.log(Number(3));//3转为3
    console.log(Number('3'),typeof Number('3'));//字符串转为3
    console.log(Number('哈哈哈'),typeof Number('哈哈哈'));//字符串转为NaN
</script>

</body>
</html>